<?php

	echo $form->create("Order",array("url"=>"/".$this->params['url']['url'],'id'=>"order_edit_form"));
	echo $form->input("id",array('label'=>__("Order Id"),"type"=>"text","readOnly"=>true,'value'=>$order['Order']['id']));
	echo $form->input("name",array("type"=>"text","readOnly"=>true,'value'=>$order['ListingPlan']['plan_info']['Plan']['title']));
	echo $form->input('listing_plan_status',array("label"=>__("Plan Status"),'options'=>array(__("Inactive"),__("Active")),'default'=>$order['ListingPlan']['status']));
	echo $form->input('status',array("label"=>__("Payment Status")));
	if(in_array($order['Order']['status'],array(Order::STATUS_INCOMPLETE,Order::STATUS_PROCESSING)))
	{
		echo $form->input("payment_completed",array("label"=>__("Payment has been received."),'type'=>"checkbox"));	
	}
	if(!in_array($order['Order']['status'],array(Order::STATUS_INCOMPLETE,Order::STATUS_PROCESSING,Order::STATUS_PENDING)) && $order['Order']['payment_type'] != Plan::PAYMENT_TRIAL)
	{	
		if($order['Order']['start_date'] && $order['Order']['start_date'] != "0000-00-00")
		{
			echo $form->input("start_date",array("type"=>"text",'readOnly'=>true));
		}
		$endDate = $form->input("end_date",array("type"=>"datePicker",'div'=>false));
		if($order['Order']['payment_type'] != Plan::PAYMENT_SUBSCRIPTION)
		{
			echo $form->input('never_expire',array('checked'=>$order['Order']['end_date'] == null ? true : false,'type'=>"checkbox","after"=>$endDate,'div'=>array("class"=>"inline_fields")));
		}else
			{
				echo '<div class="inline_fields">'.$endDate.'</div>';
			}
	}
	$adminNote =  $form->input("admin_note",array("type"=>"textarea",'label'=>__("Admin note")));
	$form->setEntity('Plan.id');
	//echo $form->input($field,array('div'=>array("class"=>"inline_fields"),"after"=>$form->input('duration_period',array("div"=>false))));
	$planFields = cri("PaidListings.Plan")->getEditateFields();
  foreach($planFields as $planField)
  {
      echo $form->input("Plan.$planField");
  }
  echo $form->input("Plan.custom_fields.fields",array("type"=>"hidden",'value'=>implode(",",$this->data['Plan']['custom_fields']['fields'])));
  echo $form->input("Plan.custom_fields.fieldsets",array("type"=>"hidden",'value'=>implode(",",$this->data['Plan']['custom_fields']['fieldsets'])));
	$javascript->link("/paid_listings/js/jquery.jstree.js",false);
	$html->css('/paid_listings/css/jstree_style.css',null,array(),false);
	$javascript->link("/paid_listings/js/field_tree.js",false);
?>
<div id="" class="fielset_block">
	<div id="loading_fields">
		
	</div>
	<div id="fielset_block_tree">
		
	</div>
</div>
	<?php echo $adminNote ?>
	<?php echo $form->end(__("Save"));
?>
<script>
	var planCategories = <?php echo $javascript->object(array_values($listCategoryIds))?>;
	var handleChanges = function()
	{
		if($('#PlanLimitImages').attr('checked'))
		{
				$('#PlanImages').parent('div').show();
				$('#PlanAllowGallery').parent('div').show();
		}else
		{
			$('#PlanImages').parent('div').hide();
			$('#PlanAllowGallery').parent('div').hide();
		}
		if($('#OrderNeverExpire').attr('checked'))
		{
			$('#OrderEndDate').attr('disabled',true).hide().prev().hide();
		}else
		{
			$('#OrderEndDate').attr('disabled',false).show().prev().show();
		}
		
	}
	$(document).ready(function(){
		$.fn.prop = function(){
		}
		$('#PlanLimitImages').change(handleChanges);
		$('#OrderNeverExpire').change(handleChanges);
		handleChanges();
		loadFieldsets();
		$('#order_edit_form').submit(setValues);
	});
	var getCheckedCategories = function()
	{
    	return planCategories;
	}
</script>